project(mpi_wrapper)
cmake_minimum_required(VERSION 2.8)
find_package(Geant4 REQUIRED)
find_package(MPI REQUIRED)
set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS})
add_library (mpi_wrapper STATIC G4VMPIsession.hh G4VMPIsession.cc G4VMPIseedGenerator.hh G4VMPIseedGenerator.cc G4UImpish.hh G4UImpish.cc G4MPIstatus.hh G4MPIstatus.cc G4MPIsession.hh G4MPIsession.cc G4MPIrandomSeedGenerator.hh G4MPIrandomSeedGenerator.cc G4MPImessenger.hh G4MPImessenger.cc G4MPImanager.hh G4MPImanager.cc G4MPIbatch.hh G4MPIbatch.cc main.cpp)
include_directories(${Geant4_INCLUDE_DIRS} ${MPI_INCLUDE_PATH})
add_definitions(${Geant4_DEFINITIONS})
target_link_libraries(mpi_wrapper ${Geant4_LIBRARIES} ${MPI_LIBRARIES})

SET (LIBRARYNAME G4UImpi)
SET (LIB_MAJOR 0)
SET (LIB_MINOR 0)
SET (LIB_RELEASE 1)

SET (HDRS G4VMPIsession.hh G4VMPIseedGenerator.hh G4UImpish.hh G4MPIstatus.hh G4MPIsession.hh G4MPIrandomSeedGenerator.hh G4MPImessenger.hh G4MPImanager.hh G4MPIbatch.hh)
SET (SRCS G4VMPIsession.cc G4VMPIseedGenerator.cc G4UImpish.cc G4MPIstatus.cc G4MPIsession.cc G4MPIrandomSeedGenerator.cc G4MPImessenger.cc G4MPImanager.cc G4MPIbatch.cc)

add_library (${LIBRARYNAME} SHARED ${HDRS} ${SRCS})

SET (_soversion ${LIB_MAJOR}.${LIB_MINOR}.${LIB_RELEASE})

set_target_properties(${LIBRARYNAME} PROPERTIES SOVERSION ${LIB_MAJOR} VERSION ${_soversion})

target_link_libraries(${LIBRARYNAME})

SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET (CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries")

install (TARGETS ${LIBRARYNAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install (FILES ${HDRS} DESTINATION ${Geant4_INCLUDE_DIR})


set(CPACK_PACKAGE_NAME ${LIBRARYNAME})
set(CPACK_PACKAGE_VENDOR "networks s.r.l.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library providing MPI support for GEANT 4-9.5")
set(CPACK_PACKAGE_VERSION ${LIB_RELEASE})
set(CPACK_PACKAGE_VERSION_MAJOR ${LIB_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${LIB_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${LIB_RELEASE})
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${Geant4_INCLUDE_DIR})
set(CPACK_DEB_COMPONENT_INSTALL ON)
#set(CPACK_MONOLITHIC_INSTALL 1)

include(CPack)
